package util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by Hasee on 2018/11/28
 */
public class SHA {
    public static  final String KEY_SHA = "SHA";

    /**
     * 加密
     * @param password
     * @return
     */
    public static  String encrypt(String password){
        BigInteger sha = null;
        byte[] byteDate = password.getBytes();

        MessageDigest md;
        try {
          md = MessageDigest.getInstance(KEY_SHA);
          md.update(byteDate);
          sha = new BigInteger(md.digest());
        }catch (NoSuchAlgorithmException e){
            e.printStackTrace();
            return null;
        }
        return sha.toString(32);
    }

}
